using Lzfy_His_Service.Models;

namespace Lzfy_His_Service.Repositories
{
    /// <summary>
    /// 银行信息仓储接口
    /// </summary>
    public interface IBankInfoRepository
    {
        /// <summary>
        /// 获取银行信息列表（分页）
        /// </summary>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="isCustomOnly">是否只查询自定义银行</param>
        /// <param name="isActiveOnly">是否只查询启用的银行</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns></returns>
        Task<(List<BankInfo> banks, int totalCount)> GetBankInfoListAsync(
            string? keyword = null, 
            bool? isCustomOnly = null, 
            bool? isActiveOnly = true, 
            int pageIndex = 1, 
            int pageSize = 20);

        /// <summary>
        /// 根据ID获取银行信息
        /// </summary>
        /// <param name="id">银行ID</param>
        /// <returns></returns>
        Task<BankInfo?> GetBankInfoByIdAsync(int id);

        /// <summary>
        /// 根据标准名称获取银行信息
        /// </summary>
        /// <param name="standardName">标准名称</param>
        /// <returns></returns>
        Task<BankInfo?> GetBankInfoByStandardNameAsync(string standardName);

        /// <summary>
        /// 创建银行信息
        /// </summary>
        /// <param name="bankInfo">银行信息</param>
        /// <returns></returns>
        Task<int> CreateBankInfoAsync(BankInfo bankInfo);

        /// <summary>
        /// 更新银行信息
        /// </summary>
        /// <param name="bankInfo">银行信息</param>
        /// <returns></returns>
        Task<bool> UpdateBankInfoAsync(BankInfo bankInfo);

        /// <summary>
        /// 删除银行信息
        /// </summary>
        /// <param name="id">银行ID</param>
        /// <returns></returns>
        Task<bool> DeleteBankInfoAsync(int id);

        /// <summary>
        /// 根据BIN码获取银行信息
        /// </summary>
        /// <param name="binCode">BIN码</param>
        /// <returns></returns>
        Task<BankInfo?> GetBankInfoByBinCodeAsync(string binCode);

        /// <summary>
        /// 根据别名获取银行信息
        /// </summary>
        /// <param name="aliasName">别名</param>
        /// <returns></returns>
        Task<BankInfo?> GetBankInfoByAliasAsync(string aliasName);

        /// <summary>
        /// 搜索银行信息
        /// </summary>
        /// <param name="keyword">关键词</param>
        /// <param name="limit">限制数量</param>
        /// <returns></returns>
        Task<List<BankInfo>> SearchBankInfoAsync(string keyword, int limit = 10);

        /// <summary>
        /// 获取所有启用的银行列表
        /// </summary>
        /// <returns></returns>
        Task<List<BankInfo>> GetAllActiveBanksAsync();

        /// <summary>
        /// 检查银行名称是否已存在
        /// </summary>
        /// <param name="standardName">标准名称</param>
        /// <param name="excludeId">排除的ID</param>
        /// <returns></returns>
        Task<bool> IsBankNameExistsAsync(string standardName, int? excludeId = null);

        /// <summary>
        /// 检查BIN码是否已存在
        /// </summary>
        /// <param name="binCode">BIN码</param>
        /// <param name="excludeBankId">排除的银行ID</param>
        /// <returns></returns>
        Task<bool> IsBinCodeExistsAsync(string binCode, int? excludeBankId = null);

        /// <summary>
        /// 检查别名是否已存在
        /// </summary>
        /// <param name="aliasName">别名</param>
        /// <param name="excludeBankId">排除的银行ID</param>
        /// <returns></returns>
        Task<bool> IsAliasExistsAsync(string aliasName, int? excludeBankId = null);

        /// <summary>
        /// 批量更新BIN码映射
        /// </summary>
        /// <param name="bankId">银行ID</param>
        /// <param name="binCodes">BIN码列表</param>
        /// <param name="updatedBy">更新人</param>
        /// <returns></returns>
        Task<bool> UpdateBankBinMappingsAsync(int bankId, List<string> binCodes, string? updatedBy = null);

        /// <summary>
        /// 批量更新银行别名
        /// </summary>
        /// <param name="bankId">银行ID</param>
        /// <param name="aliases">别名列表</param>
        /// <param name="updatedBy">更新人</param>
        /// <returns></returns>
        Task<bool> UpdateBankAliasesAsync(int bankId, List<BankAliasRequest> aliases, string? updatedBy = null);

        /// <summary>
        /// 记录变更日志
        /// </summary>
        /// <param name="log">变更日志</param>
        /// <returns></returns>
        Task<bool> LogChangeAsync(BankInfoChangeLog log);

        /// <summary>
        /// 获取银行变更日志
        /// </summary>
        /// <param name="bankId">银行ID</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns></returns>
        Task<(List<BankInfoChangeLog> logs, int totalCount)> GetChangeLogsAsync(
            int? bankId = null, 
            int pageIndex = 1, 
            int pageSize = 20);
    }
}